package com.roomio.domain;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.math.RandomUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.roomio.core.model.BaseObject;
import com.roomio.core.security.model.User;
@MappedSuperclass
public abstract class Transaction extends BaseObject {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id")
	protected Long id;
	
	@Column(unique=true, nullable=false)
	protected String transactionId= String.valueOf(RandomUtils.nextLong());
	
	
	@Column(nullable = false)
	protected String description;
	
	@Column(nullable = false)
	protected Double amount;
	
	@Column(nullable = false)
	protected String currency = "USD";
	
	@Column(nullable = false)
	protected boolean expired = false;
	
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(style = "M-")
	protected Date transactionDate= new Date();
	
	@ManyToOne(fetch = FetchType.EAGER, cascade= { CascadeType.REFRESH })
	@JoinColumn(name = "USER_OWNER_ID", nullable=false)
	protected User owner;
	

	public Transaction() {
		super();
	}
	

	public Long getId() {
		return id;
	}


	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public Date getTransactionDate() {
		return transactionDate;
	}

	public void setTransactionDate(Date transactionDate) {
		this.transactionDate = transactionDate;
	}


	public String getTransactionId() {
		return transactionId;
	}


	public void setTransactionId(String transactionId) {
		this.transactionId = transactionId;
	}


	public boolean isExpired() {
		return expired;
	}


	public void setExpired(boolean expired) {
		this.expired = expired;
	}


	public User getOwner() {
		return owner;
	}


	public void setOwner(User owner) {
		this.owner = owner;
	}
	
	

}